package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class LoginDetails {

    private ArrayList<LoginDetails> userPasswordRepository;
    private String username;
    private String password;
    private String libraryUserName;
    private String emailID;
    private String address;
    private long phoneNum;

    public ArrayList<LoginDetails> getUserPasswordRepository() {
    return this.userPasswordRepository;
    }

    public String getName() {
        return this.libraryUserName;
    }

    public String getEmailID() {
        return emailID;
    }

    public String getAddress() {
        return address;
    }

    public long getPhoneNum() {
        return phoneNum;
    }

    public void populateAllUserDetails() {
        this.userPasswordRepository = new ArrayList<LoginDetails>();
        LoginDetails detail1 = this.insert("111-1111", "john123", "John", "john123@in.com", "AnnaNagar,Madurai",43547647);
        this.userPasswordRepository.add(detail1);
        LoginDetails detail2 = this.insert("111-1112", "peter324", "Peter", "peter324@yahoo.com", "Bharati Lane,Trichy",56457879);
        this.userPasswordRepository.add(detail2);
        LoginDetails detail3 = this.insert("111-1113", "celine786","Celine","celine786@gmail.com","Peelamedu,Kovai",98778450);
        this.userPasswordRepository.add(detail3);
        LoginDetails detail4 = this.insert("111-1114", "nancy089", "Nancy", "nancy642@thoughtworks.com","Velachery,Chennai",82552677);
        this.userPasswordRepository.add(detail4);
        LoginDetails detail5 = this.insert("111-1115", "shiksha-xs", "Shiksha", "shiksha-xs@aol.com","Coal Street,Neyveli",21234556);
        this.userPasswordRepository.add(detail5);
    }

    public LoginDetails insert(String username, String password, String libraryUserName, String emailID, String address, long phoneNum) {
        LoginDetails someDetails = new LoginDetails();
        someDetails.username=username;
        someDetails.password = password;
        someDetails.libraryUserName = libraryUserName;
        someDetails.emailID = emailID;
        someDetails.address = address;
        someDetails.phoneNum = phoneNum;
        return someDetails;
    }

    public String getLoginDetailsFromUser() throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    return br.readLine();
    }

    public int searchUsername(String userName) {
        int index = 0;
        while (index < userPasswordRepository.size()&& !userPasswordRepository.get(index).username.equals(userName)){
        ++index;
        }
        return index;
    }
    public boolean verifyPassword(String password,int index ){
        if (index== userPasswordRepository.size())
        return false;
        if (userPasswordRepository.get(index).password.equals(password))
        return true;
        else
        return false;

    }

}
